package com.order.dao;

import com.order.pojo.OrderList;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface OrderListDao {
    //点菜,主键回填
    @Insert("INSERT INTO order_list(food_id,customer_id,count,order_id) " +
            "VALUES(#{food_id},#{customer_id},#{count},#{order_id})")
    Integer order(OrderList order);
    //取消某个菜(根据id)
    @Delete("DELETE FROM order_list WHERE id=#{id}")
    Boolean quit(Integer id);
    //计算出该orderId对应的总金额
    //需要联合Food表查询
    //SELECT SUM(count*food.price) FROM order_list,food WHERE order_list.food_id=food.id AND order_id=1 ;
    @Select("SELECT SUM(count*food.price) FROM order_list,food WHERE order_list.food_id=food.id AND order_id=#{orderId}")
    Double sumPrice(Integer orderId);


}
